from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, VARCHAR, DATETIME, func, ForeignKey

from config.mysql import engine

Base = declarative_base(engine)


class User(Base):
    """
    用户信息表
    """
    __tablename__ = "user"

    id = Column(Integer, primary_key=True, autoincrement=True, comment="用户id")
    name = Column(VARCHAR(50), nullable=True, comment="姓名")
    age = Column(VARCHAR(50), nullable=True, comment="年龄")
    tel = Column(VARCHAR(50), nullable=True, comment="手机号")
    address = Column(VARCHAR(100), nullable=True, comment="地址")
    createDate = Column(DATETIME(), server_default=func.now(), comment="创建时间")
    updateDate = Column(DATETIME(), server_default=func.now(), onupdate=func.now(), comment="更新时间")


class Image(Base):
    """"""
    __tablename__ = "user_image"

    id = Column(Integer, primary_key=True, autoincrement=True, comment="图片id")
    fileKey = Column(VARCHAR(250), nullable=True, comment="文件名")
    userId = Column(Integer, ForeignKey('user.id'), comment="用户id")
    createDate = Column(DATETIME(), server_default=func.now(), comment="创建时间")
    updateDate = Column(DATETIME(), server_default=func.now(), onupdate=func.now(), comment="更新时间")
